import _js from "../../cocos-libs/_/_js";
import _proxy from "../../cocos-libs/_/_proxy";
import _random from "../../cocos-libs/_/_random";


class ShopConfig extends _proxy<Record<string, IShopData>>{

    #array: IShopData[] = [];

    protected onLoad() {
        super.onLoad();
        _js.forIn(this._data, (value) => {
            this.#array.push(value);
        });
    }

    get length() {
        return _js.size(this.#array);
    }

    random() {
        return _random.arrayRandom(this.#array);
    }

    getShuffleDate(length: number): IShopData[] {
        length = Math.min(length, this.length);
        _random.shuffle(this.#array);
        let arr: IShopData[] = [];
        _js.each(length, i => {
            arr.push(this.#array[i]);
        });
        return arr;
    }

}

const shopCfg = new ShopConfig();
export default shopCfg